
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package App;

import GUI.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Jaso
 */
public class Facada {
    private LoginPanel loginPanel;
    private AccountPanel accountpanel;
    private DepositPanel depositPanel;
    private  WithdrawPanel withdrawPanel;
    private GUI myGUI;
    private Database db;
    private double currentBalance;
    
    public Facada() {
        currentBalance = 1000;
        loginPanel = new LoginPanel(this);
        depositPanel = new DepositPanel(this);
        withdrawPanel = new WithdrawPanel(this);
        accountpanel = new AccountPanel(this);
        myGUI = new GUI(this, loginPanel,accountpanel,  depositPanel, withdrawPanel );
        db = new Database();
    }
    
    
    public void initGUI()    {
        
        myGUI.setTitle("HKR BANK");
        myGUI.setVisible(true);   
    }
    
    /**
     * @return the currentBalance
     */
    public double getCurrentBalance() {
        return db.getBalance();
    }

    /**
     * @param currentBalance the currentBalance to set
     */
    public void setCurrentBalance(double currentBalance) {
        db.upDateAccountBalance(currentBalance);
    }
    
    public boolean isValidWithdrawAmount()  {
        return db.getBalance() >= withdrawPanel.getWithdrawAmount();
    }

    public boolean isValidDepositAmount()  {
        return 100 <= depositPanel.getDepositAmount();
    }
    
    
    
    public void withDrawMoney() {   
        db.upDateAccountBalance(withdrawPanel.getWithdrawAmount() * -1) ;
        withdrawPanel.updateCurrentBalance(db.getBalance());
        myGUI.SwitchPanels("account");
        JOptionPane.showMessageDialog(null, "you withdrawn " + withdrawPanel.getWithdrawAmount() + "0 Kr from your account" );
    }

    public void depositMoney()  {
        db.upDateAccountBalance(depositPanel.getDepositAmount());
        depositPanel.updateCurrentBalance(db.getBalance());
        myGUI.SwitchPanels("account");
        JOptionPane.showMessageDialog(null, depositPanel.getDepositAmount() + "0 Kr Deposited in your account ");
    }
    
    public boolean confirmLoginDetails(){

        db.setUserName(loginPanel.getAccountName());
        db.setPin(loginPanel.getPinNr());
        return db.confirmUserID();    
    }

    
}
